I am using a button :
<Button
android:text="Submit"
android:id="@+id/Button01"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</Button>
In my onCreate() event, I am calling Button01 like this:
setContentView(R.layout.main);
View Button01 = this.findViewById(R.id.Button01);
Button01.setOnClickListener(this);
There is a background in the application, and I want to set an opacity on this submit button. How can I set an opacity for this view? Is it something that I can set on the java side, or can I set in the main.xml file?
On the java side I tried Button01.mutate().SetAlpha(100), but it gave me an error
Aryan Kumar
27-Jun-2023Sure, here is how to set opacity for a view in Android:
Code snippet
In this code, we first get the view from the layout using the
findViewById()method. Then, we set the opacity of the view using thesetAlpha()method. ThesetAlpha()method takes a float value as input, which represents the opacity of the view. A value of 1.0f represents fully opaque, while a value of 0.0f represents fully transparent.In this example, we are setting the opacity of the view to 0.5f, which means that the view will be half transparent.
Anonymous User
13-Jan-2016